/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_Property_h__
#define __dylab_Property_h__

//===========================================================================================
#include <dylab/utils/Array.h>
#include <dylab/utils/types/TypeParser.h>

//===========================================================================================
namespace dylab {

    /** 
     */    
    class DYLAB_EXPORT Property
    {
    protected:            
        String mName;
        String mValue;

    public:
        Property()
                { }

        Property(const Property & _p)
            : mName(_p.mName), mValue(_p.mValue)
                { }

        Property(const String & _name, const String & _value) 
            : mName(_name), mValue(_value)
                { }

        Property(const Array<String,2> & _a)
            : mName(_a[0]), mValue(_a[1])
                { }

        virtual ~Property() 
                { }

        void setName(const String & _name) 
                { mName = _name; }

        String getName() const 
                { return mName; }

        void setValue(const String & _value) 
                { mValue = _value; }

        String getValue() const 
                { return mValue; }

        operator String() const
				{ return String::fmt("%1% = %2% ", mName, mValue); }
    };

    //===========================================================================================    
    inline std::ostream & operator << (std::ostream & _os, const Property & _o)
            { return _os << String(_o); }

    //===========================================================================================
    template <>
        inline Property TypeParser::parse(const String & _string)
            { return Property(Array<String,2>::parse(_string, "=")); }
    template <>
        inline Property TypeParser::parse(const String & _string, const Property & _defaultValue)
            {
                try { return Property(Array<String,2>::parse(_string, "=")); } 
                catch (EInvalidFormat &) { return _defaultValue; }
            }

}
//===========================================================================================
#endif // __dylab_Property_h__
